package com.chixing.ih.module.programmer.service.Impl;/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @Author MasterYan
 * @Date 2020/10/6
 * Time: 23:53
 * @version 1.0
 */

import com.chixing.ih.module.programmer.mapper.*;
import com.chixing.ih.module.programmer.pojo.dto.ProgrammerListDTO;
import com.chixing.ih.module.programmer.pojo.dto.ProgrammerEntiretyDTO;
import com.chixing.ih.module.programmer.service.IProgrammerListService;
import com.chixing.ih.util.EmptyUtil;
import com.chixing.ih.util.PageRequest;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName ProgrammerListServiceImpl
 * @Description
 * @Version 1.0
 **/
@Service
@Transactional
public class ProgrammerListServiceImpl implements IProgrammerListService {


    @Autowired
    ProgrammerMapper programmerMapper;

    @Autowired
    ImageMapper imageMapper;

    @Autowired
    WorkMapper workMapper;

    @Autowired
    EvaluateMapper evaluateMapper;
    @Autowired
    PersonalSkillMapper personalSkillMapper;

    @Autowired
    PersonalProjectMapper personalProjectMapper;


    @Override
    public ProgrammerEntiretyDTO programmer(long userId) {
        ProgrammerEntiretyDTO programmerEntiretyDTO = programmerMapper.getOneApply(userId);

        return programmerEntiretyDTO;
    }


//    @Override
//    public List<ProgrammerListDTO> programmerListDTOList(PageRequest pageRequest) {
//        if (EmptyUtil.isEmpty(pageRequest.getPageNum())) {
//            pageRequest.setPageNum(1);
//        }
//
//        if (EmptyUtil.isEmpty(pageRequest.getPageSize())) {
//            pageRequest.setPageSize(10);
//        }
//
//        List<ProgrammerListDTO> listDTOS = programmerMapper.listAll();
//        PageHelper.startPage(pageRequest.getPageNum(), pageRequest.getPageSize());
//        return listDTOS;
//
//    }

    @Override
    public List<ProgrammerListDTO> programmerListDTOList(PageRequest pageRequest, String programmerCareer, String workPlace, Integer workWay, List<Integer> list) {
        if (EmptyUtil.isEmpty(pageRequest.getPageNum())) {
            pageRequest.setPageNum(1);
        }

        if (EmptyUtil.isEmpty(pageRequest.getPageSize())) {
            pageRequest.setPageSize(10);
        }

        PageHelper.startPage(pageRequest.getPageNum(), pageRequest.getPageSize());

        List<ProgrammerListDTO> allByCondition = programmerMapper.findAllByCondition(programmerCareer, workPlace, workWay, list);
        for (ProgrammerListDTO programmerListDTO : allByCondition
        ) {
            if (programmerListDTO.getStarRating() == null) {
                programmerListDTO.setStarRating(0.0);

            }

        }

        return allByCondition;
    }
}
